vbscript is a visual basic script used in wincc flexible for hmi programming and configuration. vbscript access hmi screen items to write and read screen items value. vb script is very help full to design HMI screen. vbscript also read and write tag value by using smart tags keyword. in industrial control system vbscript help to make HMI more user friendly. vb script have many useful features like read and write tag value, read and write screen items value and screen items propertis.in this article we understand how to read and write tag value and read and write screen items property and value.
open wincc tia and than create project after creating project open your screen and then add items like button, text field, input output field, slider etc. each screen items have it's unique name. this unique name is used for accessing screen items in vb script. in this article we access screen items in vb script.
open tag table and add tag with proper data type in this article we have input1, input2 and input3 and each tag have integer (INT) data type.
tag is very important in industrial control. tag is name of variable to identify of application. each tag associated with a proper data type. Siemens HMI tags are accessible in vbscript. you can use "Smarttag" keyword to access HMI or plc tag. or press CTRL+J to access tag table in vbscript. each tag store value like temperature, area, depth etc. following are the example of wicc vbscript to access tag.
This example demonstrates how VBScript is used to assign values to tags using the SmartTags. input1, input2 and input3 are tags which are we inserted in hmi tag table, in this script we simple store values in tags. this vbscript is associated with button press events property. this subroutine vbscript executed when button pressed. following are code explanation
SmartTags
is an object that is used to store values for different keys or tags. These tags act as identifiers for certain elements in the script, allowing you to reference and update them as needed.SmartTags("input1") = 12
assigns the value 12 to the tag named "input1"
.SmartTags("input2") = 134
assigns the value 134 to the tag named "input2"
.SmartTags("input3") = 156
assigns the value 156 to the tag named "input3"
.each screen items are associated with a screen name. screen items like text field, button, input output field etc have it's unique name. in vbscript screen name and screen items name are very important to access screen items. in vb script following items property changed.
Dim items_var
Set items_var = HmiRuntime.Screens("Screen_name").ScreenItems("screen_item_name")
items_var
to hold the reference to the screen item.items_var
.Screen_name
in the HMI runtime environment. Screen_name
should be replaced with the actual name of the screen you want to reference.screen_item_name
with the actual name of the item (like a button, text field, or other UI element).above is the vbscript example of accessing screen items property in wincc. in this script we access text property of a text fild. when button is pressed than text field changed to "button is pressed", text field color changed to red and width of text filed is changed to 4. following are code explanation in simple form
items_var
to store a reference to a screen item.Text field_2
on the screen called Screen_1
and assigns it to the items_var
variable. In this case, Text field_2
could be a label, text box, or any other UI element on the screen.Text field_2
to the message "button is pressed". The Text
property modifies the content of the screen item.Text field_2
to red. The ForeColor
property is used to set the color of the text. In this case, vbRed
is a predefined constant in VBScript that represents the red color.Text field_2
screen item. The Width
property controls the horizontal size of the item. Here, it's set to 4 (the unit of measurement depends on the environment, such as pixels or other units).